package cn.chenxiejia;

import java.util.Random;
import java.util.Scanner;

/***
 * @program: var1
 * @ClassName: for01
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/1/8 14:23
 * @version : V1.0
 */
public class for01 {
    public static void main(String[] args) {
        System.out.println("游戏开始");
        Random rand = new Random();
        var num = rand.nextInt(100) + 1;
        int a = 1;
        int b = 0;
        while (true) {
            System.out.println(a + "、请输入一个数字：");
            Scanner sc = new Scanner(System.in);
//            var c = sc.nextLine();
            if (sc.hasNextInt()) {
                b = sc.nextInt();
                if (b > num) {
                    System.out.println("猜大了");
                    a++;
                } else if (b < num) {
                    System.out.println("猜小了");
                    a++;
                } else {
                    if (a > 10) {
                        System.out.println("太菜了吧，才猜对！");
                        break;
                    } else {
                        System.out.printf("恭喜你，猜对了！，您的得分是%d", 110 - a * 10);
                        break;
                    }
                }
            } else {
                var c = sc.nextLine();
                if (c.equals("exit")) {
                    System.out.println("游戏退出！");
                    break;
                } else {
                    System.out.printf("输入有误%s", c);
                    System.out.println();
                    continue;
                }
            }
        }
    }
}
